﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using COM.Rights.Model;
using COM.Rights.BLL;
using System.Text;
using System.Data;

public partial class Pages_BdReviews_Edit : ZMPageEdit<BdReviews,BdReviewsInfo>
{ 
	#region 重写方法


    protected override void OnLoading()
    {
        base.OnLoading();

        if (!IsPostBack)
        {
            BindHostName();
        }
    }


    protected override void OnAchieve()
    {
        StringBuilder sb = new StringBuilder();
        foreach (ListItem item in HostNames.Items)
        {
            if (item.Selected)
            {
                sb.Append(";");
                sb.Append(item.Value);
            }
        }
        if (!string.IsNullOrEmpty(sb.ToString()) && sb.ToString().IndexOf(";") == 0)
        {
            Model.HostName = sb.ToString().Substring(1, sb.ToString().Length - 1);
        }
        Model.ReplyBy = ZASession.Account;
        Model.ReplyDate = DateTime.Now;
        base.OnAchieve();
    }

    protected override void OnSave()
    {
        if (IsNewModel)
        {
            BdReviews br = new BdReviews();
            
            //br.a
            if (!string.IsNullOrEmpty(Model.Content)) {
              string[] contents = Model.Content.Split('|');
              foreach (string s in contents) {
                  BdReviewsInfo bri = (BdReviewsInfo)(Model.Clone());
                  bri.Content = s;
                  br.Add(bri, "*");
              }
            }
        }
        else
        {
            base.OnSave();
        }
        
    }


    protected override void OnBinding()
    {
        base.OnBinding();
        if (!IsNewModel)
        {
            string[] arr = this.Model.HostName.Split(';');
            if (arr != null && arr.Length > 0)
            {

                foreach (ListItem item in HostNames.Items)
                {
                    foreach (string host in arr)
                    {
                        if (string.Compare(host, item.Value, false) == 0)
                        {
                            item.Selected = true;
                            break;
                        }
                    }
                }
            }
        }


    }

    protected void BindHostName()
    {


        PermUserWeb _PermUserWeb = new PermUserWeb();
        List<DBParameter> _listDBParameter = new List<DBParameter>();
        _listDBParameter.Add(new DBParameter("@TranType", "hostname"));
        _listDBParameter.Add(new DBParameter("@UID", ZASession.Account));

        IDataReader sdr = _PermUserWeb.ExecuteReader("[dbo].[mdlist_sel]", _listDBParameter, System.Data.CommandType.StoredProcedure);
        DataTable dt = new DataTable();
        dt.Load(sdr);

        ZABinder.FillList(string.Empty, HostNames, false, dt);

        BdProduct _BdProduct = new BdProduct();
        List<DBParameter> _listDBParameter2 = new List<DBParameter>();
        _listDBParameter2.Add(new DBParameter("@TranType", "product"));
        IDataReader sdr2 = _PermUserWeb.ExecuteReader("[dbo].[mdlist_sel]", _listDBParameter2, System.Data.CommandType.StoredProcedure);
        DataTable dt2 = new DataTable();
        dt2.Load(sdr2);
        ZABinder.FillList(string.Empty, BdReviewsInfo_Area, true, dt2);

    }

    #endregion 	重写方法
}